<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学期" prop="semId">
        <el-select v-model="queryParams.semId" filterable clearable placeholder="请选择学期">
          <el-option
            v-for="item in semsterList"
            :key="item.id"
            :label="item.title"
            :value="item.id"
            size="small">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="教师" prop="teacherId">
          <el-select
            v-model="queryParams.teacherId"
            filterable
            remote
            reserve-keyword
            placeholder="请输入姓名选择"
            :remote-method="remoteTeacher"
            :loading="loading">
            <el-option
              v-for="item in teacherList"
              :key="item.userId"
              :label="item.name"
              :value="item.userId">
            </el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="分数范围" prop="score_start">
        <el-col :span="11">
            <el-input
              v-model="queryParams.score_start"
              placeholder="请输入打分"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-input
            v-model="queryParams.score_end"
            placeholder="请输入打分"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['evaluate:evalResults:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="evalResultsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="学期" align="center" prop="semName" />
      <el-table-column label="班级" align="center" prop="className" />
      <el-table-column label="学号" align="center" prop="stuCode" />
      <el-table-column label="姓名" align="center" prop="stuName" />
      <el-table-column label="量化考核得分" align="center" prop="quantifyScore" />
      <el-table-column label="评价得分" align="center" prop="evaluateScore" />
      <el-table-column label="综合得分" align="center" prop="score" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listEvalResults, getEvalResults, delEvalResults, updateEvalResults, exportEvalResults } from "@/api/evaluate/evalResults";
import { selectTeacher} from "@/api/base/teacher";
import { selectSemster} from "@/api/base/semster";

export default {
  name: "EvalResults",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 教师数据
      teacherList: [],
      // 评教结果表格数据
      evalResultsList: [],
      // 学期数据
      semsterList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        semId: null,
        teacherId: null,
        score_start: null,
        score_end: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        semId: [
          { required: true, message: "学期不能为空", trigger: "blur" }
        ],
        teacherId: [
          { required: true, message: "教师不能为空", trigger: "blur" }
        ],
        score: [
          { required: true, message: "打分不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    selectSemster({'status':1}).then(response => {
      this.semsterList = response.rows;
    });
  },
  methods: {
    /** 查询评教结果列表 */
    getList() {
      this.loading = true;
      listEvalResults(this.queryParams).then(response => {
        this.evalResultsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    remoteTeacher(query) {
      if (query !== '') {
          this.loading = true;
          selectTeacher({name:query}).then(response => {
            this.teacherList = response.rows;
            this.total = response.total;
            this.loading = false;
          });
      } else {
         this.teacherList = [];
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        semId: null,
        teacherId: null,
        score: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有评教结果数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportEvalResults(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
